package com.esyoga.yoyoga.handler;

import com.esyoga.yoyoga.pojo.DTO.ReviewDTO;
import com.esyoga.yoyoga.pojo.TReview;
import com.esyoga.yoyoga.service.ReviewService;
import lombok.Data;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/*
评论表
 */
@Data
@Controller
@RequestMapping("/review")
public class ReviewHandler {
    @Resource
    ReviewService reviewService;
    @RequestMapping("/addReview")
    @ResponseBody
    //添加一个评论
    public String addReview(TReview tReview, HttpServletRequest request){
       // request.getSession().getAttribute("");
       tReview.setrUserid(3);
        tReview.setrUsertype(0);
       // System.out.println(tReview);
        int row = reviewService.addReview(tReview);
        if (row>0)
            return "添加评论成功";
        else
            return "添加评论失败";
    }
    //展示动态下的所有评论，根据动态的id
    @RequestMapping("/findAllReviewByMid")
    @ResponseBody
    public List<ReviewDTO>findAllReviewByMid(Integer mid){
        List<ReviewDTO> reviewDTOS= reviewService.findAllReviewByMid(mid);
        return reviewDTOS;
    }

    //根据评论id删除评论
    @RequestMapping("/delOneReview")
    @ResponseBody
    public String delOneReview(Integer rid){
       String result= reviewService.delOneReview(rid);
        return result;
    }

}
